#include <machine/asm.h>

ENTRY(strncpy)
	movl	4(%sp),%d0		| return value is toaddr
	movl	12(%sp),%d1		| count
	jeq	.Lscdone		| nothing to do
	movl	8(%sp),%a0		| a0 = fromaddr
	movl	%d0,%a1			| a1 = toaddr
	subql	#1,%d1
.Lscloop:
	movb	(%a0)+,(%a1)+		| copy a byte
#ifndef __mcoldfire__
	dbeq	%d1,.Lscloop		| loop through low word of d1
#endif
	jeq	.Lscpadding		| copied null, padding if necessary
#ifndef __mcoldfire__
	clrw	%d1			| clear low word of d1
#endif
	subql	#1,%d1			| adjust count for long copies
	jcc	.Lscloop		| more room, keep going
.Lscdone:
#ifdef __SVR4_ABI__
	moveal	%d0,%a0
#endif
	rts

.Lscploop:
	clrb	(%a1)+			| clear a byte
#ifndef __mcoldfire__
	dbra	%d1,.Lscploop		| keep going
	clrw	%d1
#endif
.Lscpadding:
	subql	#1,%d1
	jcc	.Lscploop
	jra	.Lscdone
END(strncpy)
